package com.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

//配置swagger
@Configuration
@EnableSwagger2
public class Swagger {

    //配置了swagge
    //enable是否启用swagger
    @Bean
    public Docket docket(Environment environment){
        //设置显示的swagger环境
        Profiles profiles=Profiles.of("dev","test");
        //通过enviroment。acceptsProfiles 判断是否处在自己设定的环境当中
        boolean flag=environment.acceptsProfiles(profiles);
         //获取项目的环境；


        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("小庆")  //分组
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.swagger.controller"))
                //过滤路径
               // .paths(PathSelectors.ant("/com/***"))
                .build();
    }
    //配置swagger信息
    private ApiInfo apiInfo(){
        Contact DEFAULT_CONTACT = new Contact("小庆", "baidu.com", "1578442339@qq.ccom");
      return   new ApiInfo("Swagger的api文档",
              "xxxxx",
              "1.0",
              "baidu.com",
              DEFAULT_CONTACT,
              "Apache 2.0",
              "http://www.apache.org/licenses/LICENSE-2.0",
              new ArrayList());

    }


}
